package com.boken.caelum;
import com.plugin.mybatis.generator.TestDefaultShellCallback135;
import org.junit.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GeneratorMain {

    @Test
    public void generator() throws IOException, XMLParserException, InvalidConfigurationException, SQLException, InterruptedException {
        File s = new File("");
        String absolutePath = s.getAbsolutePath();
        System.out.println("-----获取模块绝对路径absolutePath："+absolutePath);
        //全局设置 项目名目录
        String targetProjectPrefix = absolutePath + "/";
        System.setProperty("targetProjectPrefix",targetProjectPrefix);


        //jdbc驱动包位置
        //String jdbcPath = "d:\\.m2\\repository\\mysql\\mysql-connector-java\\5.1.41\\mysql-connector-java-5.1.41.jar";
        //System.setProperty("jdbcPath",jdbcPath);

        //generatorConfig.xml位置
        String generatorConfigPath = absolutePath + "\\src\\main\\resources\\generatorConfig11.xml";

        List<String> warnings = new ArrayList<>();
        File configFile = new File(generatorConfigPath);
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new TestDefaultShellCallback135(true);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }
}